package com.atguigu.weixin.controller;

import java.lang.reflect.InvocationTargetException;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.atguigu.crud.bean.Wxqr;
import com.atguigu.crud.service.WxqrService;

/**
 * 微信二维码、扫描登录、临时二维码、永久二维码等等功能 
 * @author Administrator
 *	public final static int MAX_BASE_SNUM=100000;//十万以上是临时的，十万以下是永久的
 */
@Controller
@RequestMapping("/wqr")
public class WeixinQrController {
	@Autowired
	private WxqrService wxqrService;
	
	
	@RequestMapping("/list/{type}")
	public String list(@PathVariable String type,Model model) {
		//临时二维骊
		if("temp".equals(type)) {
			model.addAttribute("datas", wxqrService.listTempQr());
		} else {
			model.addAttribute("datas", wxqrService.listBaseQr());
		}
		return "admin/wqr/list";
	}
	
	@RequestMapping(value="/add",method=RequestMethod.GET)
	public String add(Model model) {
		model.addAttribute("wq", new Wxqr());
		return "admin/wqr/add";
	}
	
	@RequestMapping(value="/add",method=RequestMethod.POST)
	public String add(Wxqr wq) throws IllegalAccessException, InvocationTargetException  {
		wq.setStatus(1);
		wxqrService.add(wq);
		return "redirect:/wqr/list/base";
	}

	
}
